package com.lanxin.xx.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDate;
import com.baomidou.mybatisplus.annotation.TableId;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; // 导入格式化工具类
import java.io.Serializable;

/**
 * <p>
 *
 * </p>
 *
 * @author zyq
 * @since 2025-07-26
 */
@TableName("xx_information")
public class XxInformation implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "oid", type = IdType.AUTO)
    private Integer oid;

    private Integer typeid;

    private String title;

    private String content;

    @TableField(value = "publishDate")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime publishDate;

    // 新增：用于JSP展示的格式化日期字符串（无需数据库映射）
    @TableField(exist = false) // 表示该字段不是数据库字段
    private String publishDateStr;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @TableField(value = "closeDate")
    private LocalDate closeDate;

    private Integer creator;

    private String file;

    //添加publishDateStr的getter方法，自动格式化LocalDateTime
    public String getPublishDateStr() {
        if (publishDate != null) {
            // 将LocalDateTime格式化为"yyyy-MM-dd HH:mm:ss"字符串
            return publishDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        }
        return ""; // 如果日期为null，返回空字符串
    }

    //（解决500报错）
    //添加closeDateStr的getter方法（方法名getCloseDateStr）
    public String getCloseDateStr() {
        // 处理null值，避免空指针
        if (closeDate == null) {
            return ""; // 或返回"无停止时间"
        }
        // 格式化日期为"yyyy-MM-dd"
        return closeDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    public Integer getOid() {
        return oid;
    }

    public void setOid(Integer oid) {
        this.oid = oid;
    }
    public Integer getTypeid() {
        return typeid;
    }

    public void setTypeid(Integer typeid) {
        this.typeid = typeid;
    }
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
    public LocalDateTime getPublishDate() {
        return publishDate;
    }

    public void setPublishDate(LocalDateTime publishDate) {
        this.publishDate = publishDate;
    }
    public LocalDate getCloseDate() {
        return closeDate;
    }

    public void setCloseDate(LocalDate closeDate) {
        this.closeDate = closeDate;
    }
    public Integer getCreator() {
        return creator;
    }

    public void setCreator(Integer creator) {
        this.creator = creator;
    }
    public String getFile() {
        return file;
    }

    public void setFile(String file) {
        this.file = file;
    }

    @Override
    public String toString() {
        return "XxInformation{" +
                "oid=" + oid +
                ", typeid=" + typeid +
                ", title=" + title +
                ", content=" + content +
                ", publishDate=" + publishDate +
                ", closeDate=" + closeDate +
                ", creator=" + creator +
                ", file=" + file +
                "}";
    }
}